package com.moli.iov.admin.web.controller;

import com.moli.iov.admin.service.IUploadService;
import com.moli.iov.rest.RestResponse;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 文件上传
 * </p>
 *
 * @author zql
 * @since 2019/9/10 10:12
 */
@Slf4j
@RestController
public class UploadController {

  @Autowired
  private IUploadService picUploadService;

  /**
   * OSS上传文件
   * @param multipartFile
   * @return
   */
  @RequestMapping("/ueditor/php/upload/image/id")
  public RestResponse upload(@RequestParam("file") MultipartFile multipartFile) {
    try {
      return picUploadService.upload(multipartFile);
    } catch (IOException e) {
      log.error("OSS上传文件 异常", e);
      return RestResponse.failure("上传失败");
    }
  }
}
